package com.zxy.ziems.server.controller;

import com.zxy.btp.common.response.JsonResponse;
import com.zxy.btp.common.response.PageResult;
import com.zxy.ziems.server.domain.PointData;
import com.zxy.ziems.server.dto.PointDataDto;
import com.zxy.ziems.server.dto.PointDataQueryDto;
import com.zxy.ziems.server.service.PointDataService;
import com.zxy.ziems.server.vo.PointDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @ClassName PointDataController
 * @Description
 * @Author 邓伟
 * @Date 2023/12/4 13:47
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/pointData")
public class PointDataController {

    @Autowired
    private PointDataService pointDataService;

    @PostMapping("/pageList")
    public JsonResponse<PageResult<PointDataVo>> pageList (@RequestBody PointDataQueryDto pointDataQueryDto) {
        PageResult<PointDataVo> pageResult = pointDataService.pageList(pointDataQueryDto);
        return JsonResponse.SUCCESS(pageResult);
    }

    @PostMapping("/update")
    public JsonResponse update (@RequestBody @Validated PointDataDto pointDataDto) {
        pointDataService.updateData(pointDataDto);
        return JsonResponse.SUCCESS();
    }

    @PostMapping("/export")
    public JsonResponse export (@RequestParam("file") MultipartFile file, @RequestParam(value = "classifyId") String classifyId) throws IOException {
        pointDataService.export(file,classifyId);
        return JsonResponse.SUCCESS();
    }


}
